var util={
	slice:function(str,start,end){
		return [].slice.call(str,start,end).join(',').replace(/[,]/g,'');
	}
}
var bird={
	//单例模式
	div:document.getElementsByClassName('bird')[0],
	downsid:null,//下降定时器
	fallspeed:1,//下降速度
	speed:0.5,//加速度
	inittop:200,//初始高度
	left:50,//左侧位置
	show:function(){
		this.div.style.display='block';
	},
	falldown:function(){
		//下降
		var upimg=['img/up_bird0.png','img/up_bird1.png'];
		var downimg=['img/down_bird0.png','img/down_bird1.png'];
		var index=0;
		var that=this;
		this.downsid=setInterval(function(){
			that.fallspeed+=that.speed;
//			console.log(that.div);
			that.div.style.top=(+util.slice((window.getComputedStyle(that.div).top),0,-2)+that.fallspeed)+'px';
			if(that.fallspeed>0){
				that.div.style.backgroundImage="url("+downimg[index]+')';
			}else if(that.fallspeed<0){
				that.div.style.backgroundImage="url("+upimg[index]+')';
			}
			if(index<upimg.length-1){
				index++;
			}else{
				index=0;
			}
			that.isout();
			
		},40)
	},
	isout:function(){
		//判断是否出界
		var top=+util.slice(this.div.style.top,0,-2);//当前高度
//		console.log(top);
		if(top<0){
			this.div.style.top=0;
			this.fallspeed=0;
		} else if(top>wrapHeight){
			//摔死了,结束
			clearInterval(this.downsid);
			this.init();
			end();
		}
		
	},
	init:function(){
		//初始化小鸟数据
		this.div.style.top=this.inittop+'px';
		this.fallspeed=1;
	}

}
